<?php

/**
 * Formulaire d'inscription 
 */
class Inscription_Form_Inscription extends Zend_Form {

    /**
     * Initialise le formulaire d'inscripion en créant les champs suivants :
     *  - Login
     *  - Pwd
     */
    public function init() {
        $this->setMethod('post');
        $this->addElementPrefixPath('ZendTremplin_Decorator', 'ZendTremplin/decorator/', 'decorator');

        // Initialisation du champ login
        $login = new Zend_Form_Element_Text('login');
        $login->addFilter('StringTrim')
                ->addFilter('htmlEntities')
                ->addValidator('StringLength', false, array(3, 50))
                ->setRequired(true)
                ->setLabel('Login')
                ->setAttrib('maxLength', 50)
                ->setDecorators(array('Default'));
        $validator = new ZendTremplin_Validate_UserInscription();
        $login->addValidator($validator, true);
        $this->addElement($login);

        // Initiation du champ password
        $pwd = new Zend_Form_Element_Password('pwd');
        $pwd->addFilter('StringTrim')
                ->addValidator('StringLength', false, array(3, 10))
                ->setRequired(true)
                ->setLabel('Password')
                ->setAttrib('maxLength', 10)
                ->setDecorators(array('Default'));
        $this->addElement($pwd);

        // Ajout du bouton d'inscription
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Register')
                ->setDecorators(array(
                    'ViewHelper',
                    array(array('td' => 'HtmlTag'), array('tag' => 'td', 'colspan' => 2)),
                    array(array('tr' => 'HtmlTag'), array('tag' => 'tr'))
                ));
        $this->addElement($submit);

        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div')),
            'Form'
                )
        );
    }

}

